<!--
 * @Author: 孙大大
 * @Date: 2022-04-09 19:29:39
 * @LastEditTime: 2022-04-12 17:41:29
 * @FilePath: \黑马面面\src\views\questions\choice\tab.vue
-->
<template>
  <div class="tab-container">
    <el-tabs
      v-model="activeName"
      type="card"
      @tab-click="handleClick"
      @click="checkPermission"
    >
      <el-tab-pane label="全部" name="first">
        <search :params="params" key="1"></search>
      </el-tab-pane>
      <el-tab-pane label="待审核" name="second">
        <search
          :key="2"
          :tableData1="tableData"
          :index="index"
          ref="one"
          :params="params"
        ></search>
      </el-tab-pane>
      <el-tab-pane label="已审核" name="third">
        <search
          :key="3"
          :tableData1="tableData"
          :index="index"
          ref="two"
          :params="params"
        ></search>
      </el-tab-pane>
      <el-tab-pane label="已拒绝" name="fourth">
        <search
          :key="4"
          :tableData1="tableData"
          :index="index"
          ref="three"
          :params="params"
        ></search>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import search from "./search.vue";
import { checkState } from "@/api/questions";
export default {
  components: {
    search,
  },
  data() {
    return {
      activeName: "first",
      page: 1,
      pagesize: 5,
      tableData: [],
      index: "",
      params: "",
    };
  },
  methods: {
    updataTableData(data) {
      // this.$refs.search.updataTableData(data);
      this.params = data;
    },
    async handleClick(tab) {
      if (tab.index == 1) {
        let res = await checkState({
          page: this.page,
          pagesize: this.pagesize,
          chkState: 0,
        });
        this.index = tab.index;
        // console.log(34343434, res);
        this.tableData = res;
        // console.log("11111", this.tableData);
        this.$nextTick(() => this.$refs.one.changeTableData());
      } else if (tab.index == 2) {
        let res = await checkState({
          page: this.page,
          pagesize: this.pagesize,
          chkState: 1,
        });
        this.index = tab.index;
        // console.log(34343434, res);
        this.tableData = res;
        // console.log("11111", this.tableData);
        this.$nextTick(() => this.$refs.two.changeTableData());
      } else if (tab.index == 3) {
        let res = await checkState({
          page: this.page,
          pagesize: this.pagesize,
          chkState: 2,
        });
        this.index = tab.index;
        // console.log(34343434, res);
        this.tableData = res;
        // console.log("11111", this.tableData);
        this.$nextTick(() => this.$refs.three.changeTableData());
      }
    },
  },
};
</script>
<style lang="less" scoped></style>
